package YAPserver.mods;

import YAPenvironment.YAPconstant.ModState;
import YAPserver.behaviours.BounceDynamic;
import YAPserver.behaviours.BounceFromPlayer;
import YAPserver.behaviours.BounceMirror;
import YAPserver.behaviours.BounceToPlayer;
import YAPserver.gameObjects.Mod;
import YAPserver.logic.GameModifier;
import YAPserver.logic.Player;
/**
 * A local ModBehaviour. Also known as Missile-Mod.
 * When this modBehaviour's modify method is called it causes all ballAbstracts to aim like missiles at the specified player's wall.
 * Its demodify method reverts this action back to normal. Note that any ball's whose speed has been changed while this method is called will keep their speed.
 * The demodify method is called once the mod's timer has hit 0.
 * @author Daniel
 *
 */
public class ModBounceToPlayer extends AbstractStandardMod{
	
	private static String C_name = "ModBounceToPlayer";
	private static String C_player = "ModBounceToPlayer_player"; //I would like to change this name
	@Override
	public void modify(Mod mod, GameModifier gameMod, Player player) {
		super.modify(mod, gameMod, player);
		gameMod.addModActive(mod);
		if(gameMod.getActivations(C_player) != player.getId() || gameMod.getActivations(C_name)<=0){
			gameMod.setAllSliderBehaviour(new BounceToPlayer(player));
			gameMod.setAllWallBounce(new BounceToPlayer(player));
			//this will set the speed it will bounce at
			double speed = gameMod.getBalls(0).getSpeed();
			player.getSlider().setBounceBehaviour(new BounceFromPlayer(speed));
			player.getWall().setBounceBehaviour(new BounceFromPlayer(speed));
			gameMod.setActivation(C_player, player.getId());
			gameMod.setActivation(C_name, 0);
		}
		gameMod.addActivation(C_name);
		mod.setTimerOn(true);
	}

	@Override
	public void deModify(Mod mod, GameModifier gameMod, Player player) {
		gameMod.removeModActive(mod);
		if(gameMod.getActivations(C_player) == player.getId()){
			gameMod.subtractActivation(C_name);
			if(gameMod.getActivations(C_name)<=0){
				gameMod.setAllWallBounce(new BounceMirror());
				gameMod.setAllSliderBehaviour(new BounceDynamic());
			}
		}
	}

	@Override
	public ModState getType() {
		return ModState.player;
	}

}
